package com.dlb.andorid.presenter;

import com.dlb.andorid.XAPI;
import com.dlb.andorid.XContract;
import com.dlb.andorid.XPresenter;
import com.dlb.andorid.XServerMsg;
import com.dlb.andorid.bean.PeripheryShop;
import com.dlb.andorid.bean.ProductBean;
import com.dlb.andorid.bean.ServerResult;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

public class ZbhdPresenter extends XPresenter {

	XContract.IZbhdView iView;

	public ZbhdPresenter(XContract.IZbhdView iView) {
		super(iView);
		this.iView = iView;
	}

	public void getZbhdList(long address_id) {
		mModel.getZbhdList(address_id);
	}

	public void getZbhdInfo(long periphery_shop_id, int page) {
		mModel.getZbhdInfo(periphery_shop_id,page);
	}

	public void addCar(long id, String userId, int num, long typeId, float price) {
		mModel.addCar(id, userId, num, typeId, price);
	}



	@Override
	public void onDataSuccess(int vocational_id, HashMap<String, Object> exData, Object data) {
		super.onDataSuccess(vocational_id, exData, data);
		switch (vocational_id){
			case XAPI.GET_ZBHD_LIST_VOCATIONAL_ID:
				iView.getZbhdListSuccess(((XServerMsg<List<PeripheryShop>>)data).getData());
				break;
			case XAPI.GET_ZBHD_INFO_VOCATIONAL_ID:
				iView.getZbhdInfoSuccess(((XServerMsg<List<ProductBean>>)data).getData());
				break;
			case XAPI.ADD_CAR_VOCATIONAL_ID:
				iView.addCarSuccess(((XServerMsg<ServerResult>) data).getData());
				break;
		}
	}

	@Override
	public void onDataError(int vocational_id, HashMap exdata, Throwable throwable) {
		super.onDataError(vocational_id, exdata, throwable);

		switch (vocational_id){
			case XAPI.GET_ZBHD_LIST_VOCATIONAL_ID:
				iView.getZbhdListSuccess(new ArrayList<PeripheryShop>());
				break;
			case XAPI.GET_ZBHD_INFO_VOCATIONAL_ID:
				iView.getZbhdInfoSuccess(new ArrayList<ProductBean>());
				break;
		}


	}
}
